package com.ygou.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ygou.mapper.BrowfavMapper;
import com.ygou.pojo.Browfav;
import com.ygou.pojo.BrowfavExample;
import com.ygou.pojo.BrowfavExample.Criteria;
import com.ygou.service.BrowfavService;
@Service
public class BrowfavServiceImpl implements BrowfavService {
	@Autowired
	BrowfavMapper browfavMapper;
	@Override
	public boolean insert(Browfav record) {
		return browfavMapper.insert(record)>0;
	}

	@Override
	public boolean updateByPrimaryKey(Browfav record) {
		return browfavMapper.updateByPrimaryKey(record)>0;
	}

	@Override
	public Browfav selectByExample(int userid,int goodsid,int browfavtype) {
		BrowfavExample example=new BrowfavExample();
		Criteria c=example.createCriteria();
		c.andUseridEqualTo(userid);
		c.andGoodsidEqualTo(goodsid);
		c.andBrowfavtypeEqualTo((byte)browfavtype);
		if(browfavMapper.selectByExample(example).size()!=0) return browfavMapper.selectByExample(example).get(0);
		return null;
	}

	@Override
	public boolean deleteByPrimaryKey(Integer id) {
		return browfavMapper.deleteByPrimaryKey(id)>0;
	}
	
	/********************/
	@Override
	public List<Browfav> selectByExampleById(int userid) {
		BrowfavExample e=new BrowfavExample();
		Criteria c = e.createCriteria();
		if(!"".equals(userid)){
			c.andUseridEqualTo(userid);
		}
		c.andBrowfavtypeEqualTo((byte)1);
		e.setOrderByClause("b.lasttime desc");
		List<Browfav> ls1=browfavMapper.selectByExample(e);
		return ls1;
	}

	@Override
	public List<Browfav> selectByWhere(int userid) {
		BrowfavExample e = new BrowfavExample();
		Criteria c = e.createCriteria();
		if(!"".equals(userid)){
			c.andUseridEqualTo(userid);
		}
		c.andBrowfavtypeEqualTo((byte)2);
		e.setOrderByClause("b.lasttime desc");
		List<Browfav> brow = browfavMapper.selectByExample(e);
		return brow;
	}

}
